﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace EFCore.Models;

public partial class MyDbContext : DbContext
{
    public MyDbContext()
    {
    }

    public MyDbContext(DbContextOptions<MyDbContext> options)
        : base(options)
    {
    }

    public virtual DbSet<AspNetRole> AspNetRoles { get; set; }

    public virtual DbSet<AspNetRoleClaim> AspNetRoleClaims { get; set; }

    public virtual DbSet<AspNetUser> AspNetUsers { get; set; }

    public virtual DbSet<AspNetUserClaim> AspNetUserClaims { get; set; }

    public virtual DbSet<AspNetUserLogin> AspNetUserLogins { get; set; }

    public virtual DbSet<AspNetUserToken> AspNetUserTokens { get; set; }

    public virtual DbSet<Box> Boxes { get; set; }

    public virtual DbSet<BoxGrid> BoxGrids { get; set; }

    public virtual DbSet<CusetomOrder> CusetomOrders { get; set; }

    public virtual DbSet<CusetomOrderLine> CusetomOrderLines { get; set; }

    public virtual DbSet<Inlethouse> Inlethouses { get; set; }

    public virtual DbSet<CustomCheckList> CustomCheckList { get; set; }

    public virtual DbSet<InlethouseLine> InlethouseLines { get; set; }

    public virtual DbSet<Lognote> Lognotes { get; set; }

    public virtual DbSet<MaterialBase> MaterialBases { get; set; }

    public virtual DbSet<MaterialOrder> MaterialOrders { get; set; }

    public virtual DbSet<MaterialProperty> MaterialProperties { get; set; }

    public virtual DbSet<MyUser> MyUsers { get; set; }

    public virtual DbSet<NeetOutMaterial> NeetOutMaterials { get; set; }

    public virtual DbSet<TaskOrder> TaskOrders { get; set; }

    public virtual DbSet<ViewBox> ViewBoxes { get; set; }

    public virtual DbSet<ViewBoxWarehouseLine> ViewBoxWarehouseLines { get; set; }

    public virtual DbSet<ViewMaterial> ViewMaterials { get; set; }

    public virtual DbSet<ViewMaterialWarehouseLine> ViewMaterialWarehouseLines { get; set; }

    public virtual DbSet<ViewNeetOutMaterial> ViewNeetOutMaterials { get; set; }

    public virtual DbSet<ViewTaskOrder> ViewTaskOrders { get; set; }

    public virtual DbSet<Warehouse> Warehouses { get; set; }

    public virtual DbSet<WarehouseLine> WarehouseLines { get; set; }

    public virtual DbSet<WorkerOrder> WorkerOrders { get; set; }


    //string connstr = "Data Source=.;Initial Catalog=WareHouse_Czml;Integrated Security=false;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=True;User ID=sa;Password=yinghuayuhangyuan@121";
    string connstr = "Data Source=SVCN5EFLOWSQL01;Initial Catalog=WareHouse_Czml;Integrated Security=false;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=True;User ID=FSROBOT;Password=FSrobot,123";
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer(connstr);
    //192.168.2.114
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AspNetUser>(entity =>
        {
            entity.HasMany(d => d.Roles).WithMany(p => p.Users)
                .UsingEntity<Dictionary<string, object>>(
                    "AspNetUserRole",
                    r => r.HasOne<AspNetRole>().WithMany().HasForeignKey("RoleId"),
                    l => l.HasOne<AspNetUser>().WithMany().HasForeignKey("UserId"),
                    j =>
                    {
                        j.HasKey("UserId", "RoleId");
                        j.ToTable("AspNetUserRoles");
                    });
        });

        modelBuilder.Entity<Box>(entity =>
        {
            entity.Property(e => e.IdBox).ValueGeneratedNever();
            entity.Property(e => e.BoxGridQuantity).HasComment("格口数");
            entity.Property(e => e.DePth).HasComment("深");
            entity.Property(e => e.Height).HasComment("高");
            entity.Property(e => e.IsEnable).HasComment("允许使用");
            entity.Property(e => e.Type).HasComment("类型");
            entity.Property(e => e.VirtualSpace).HasComment("是否使用虚拟储位");
            entity.Property(e => e.Width).HasComment("宽");
        });

        modelBuilder.Entity<BoxGrid>(entity =>
        {
            entity.Property(e => e.IdBoxGrid).ValueGeneratedNever();
            entity.Property(e => e.BoxGridCode).HasComment("格口号");
            entity.Property(e => e.BoxPositionQuantity).HasComment("储位数");
            entity.Property(e => e.Sequence).HasComment("格口序号");
        });

        modelBuilder.Entity<CusetomOrder>(entity =>
        {
            entity.Property(e => e.CusetomOrderId).ValueGeneratedNever();
        });

        modelBuilder.Entity<CusetomOrderLine>(entity =>
        {
            entity.Property(e => e.CusetomOrderLineId).ValueGeneratedNever();
        });

        modelBuilder.Entity<CustomCheckList>(entity =>
        {
            entity.Property(e => e.CustomCheckList_Id).ValueGeneratedNever();
            entity.Property(e => e.Consumer_MaterialId).HasComment("消费物料号");
            entity.Property(e => e.CreateTime).HasComment("创建时间");
            entity.Property(e => e.IsCheck).HasComment("是否检查");
            entity.Property(e => e.IsExist).HasComment("是否存在");
            entity.Property(e => e.UpdateTime).HasComment("更新时间");
        });
        modelBuilder.Entity<Inlethouse>(entity =>
        {
            entity.Property(e => e.IdInlethouse).ValueGeneratedNever();
            entity.Property(e => e.InlethouseCode).HasComment("仓库号");
            entity.Property(e => e.InlethouseName).HasComment("仓库描述");
            entity.Property(e => e.Parameter).HasComment("参数");
            entity.Property(e => e.Xaxis).HasComment("排");
            entity.Property(e => e.Yaxis).HasComment("高");
            entity.Property(e => e.Zaxis).HasComment("列");
        });

        modelBuilder.Entity<InlethouseLine>(entity =>
        {
            entity.Property(e => e.IdInlethouseLine).ValueGeneratedNever();
            entity.Property(e => e.IsEnable).HasComment("是否使能");
            entity.Property(e => e.Type).HasComment("入口/出口");
            entity.Property(e => e.Xaxis).HasComment("排");
            entity.Property(e => e.Yaxis).HasComment("高");
            entity.Property(e => e.Zaxis).HasComment("列");
        });

        modelBuilder.Entity<Lognote>(entity =>
        {
            entity.Property(e => e.IdLogNote).ValueGeneratedNever();
            entity.Property(e => e.Batch).HasComment("批次");
            entity.Property(e => e.BoxCode).HasComment("料盒");
            entity.Property(e => e.Definition).HasComment("说明");
            entity.Property(e => e.MaterialCode).HasComment("物料编码");
            entity.Property(e => e.MaterialName).HasComment("物料名称");
            entity.Property(e => e.OrderNo).HasComment("工单号");
            entity.Property(e => e.Size).HasComment("大小");
            entity.Property(e => e.WarehouseLineCode).HasComment("位置");
        });

        modelBuilder.Entity<MaterialBase>(entity =>
        {
            entity.Property(e => e.IdMaterialbase).ValueGeneratedNever();
            entity.Property(e => e.IsDelete).HasComment("是否删除");
            entity.Property(e => e.MaterialCode).HasComment("Lpn");
            entity.Property(e => e.MaterialName).HasComment("物料号");
            entity.Property(e => e.Quantity).HasComment("1个单位物料数量");

            entity.HasOne(d => d.MaterialPropertyMaterialProerty).WithMany(p => p.MaterialBases).OnDelete(DeleteBehavior.ClientSetNull);
        });

        modelBuilder.Entity<MaterialOrder>(entity =>
        {
            entity.Property(e => e.IdMaterialOder).ValueGeneratedNever();
            entity.Property(e => e.MaterialOrderName).HasComment("工单名");
            entity.Property(e => e.Type).HasComment("入库or出库");

            entity.HasMany(d => d.MaterialBasesIdMaterialbases).WithMany(p => p.MaterialOrdersIdMaterialOders)
                .UsingEntity<Dictionary<string, object>>(
                    "TMaterialBasesMaterialOrder",
                    r => r.HasOne<MaterialBase>().WithMany().HasForeignKey("MaterialBasesIdMaterialbase"),
                    l => l.HasOne<MaterialOrder>().WithMany().HasForeignKey("MaterialOrdersIdMaterialOder"),
                    j =>
                    {
                        j.HasKey("MaterialOrdersIdMaterialOder", "MaterialBasesIdMaterialbase");
                        j.ToTable("T_MaterialBases_MaterialOrders");
                        j.IndexerProperty<Guid>("MaterialOrdersIdMaterialOder").HasColumnName("MaterialOrdersId_MaterialOder");
                        j.IndexerProperty<Guid>("MaterialBasesIdMaterialbase").HasColumnName("materialBasesId_Materialbase");
                    });
        });

        modelBuilder.Entity<MaterialProperty>(entity =>
        {
            entity.Property(e => e.MaterialProertyid).ValueGeneratedNever();
            entity.Property(e => e.Batch).HasComment("批次号");
            entity.Property(e => e.Description).HasComment("说明");
            entity.Property(e => e.MaterialProertyname).HasComment("属性名称");
            entity.Property(e => e.Size).HasComment("物料大小");
            entity.Property(e => e.Type).HasComment("类型");
            entity.Property(e => e.Unit).HasComment("单位");
        });

        modelBuilder.Entity<NeetOutMaterial>(entity =>
        {
            entity.Property(e => e.IdNeetOutMaterial).ValueGeneratedNever();
            entity.Property(e => e.MoCode).HasComment("工单号");
            entity.Property(e => e.NeetQuantity).HasComment("需求数量");
            entity.Property(e => e.OrderNo).HasComment("需求工单");
            entity.Property(e => e.Remark).HasComment(" 说明-实际需求数量");
            entity.Property(e => e.SlotNum).HasComment("站位号");
        });

        modelBuilder.Entity<TaskOrder>(entity =>
        {
            entity.Property(e => e.IdTaskOrder).ValueGeneratedNever();
            entity.Property(e => e.GroupPriority).HasComment("组优先级");
            entity.Property(e => e.InlethouseCode).HasComment("缓存坐标");
            entity.Property(e => e.State).HasComment("任务状态-未下发/已下发");
            entity.Property(e => e.TaskOrderCode).HasComment("任务号");
            entity.Property(e => e.TaskPriority).HasComment("任务优先级");
            entity.Property(e => e.Type).HasComment("任务类型");
            entity.Property(e => e.WarehouseCode).HasComment("仓库坐标");
        });

        modelBuilder.Entity<ViewBox>(entity =>
        {
            entity.ToView("View_Box");
        });

        modelBuilder.Entity<ViewBoxWarehouseLine>(entity =>
        {
            entity.ToView("View_Box_WarehouseLine");
        });

        modelBuilder.Entity<ViewMaterial>(entity =>
        {
            entity.ToView("View_Material");
        });

        modelBuilder.Entity<ViewMaterialWarehouseLine>(entity =>
        {
            entity.ToView("View_Material_WarehouseLine");
        });

        modelBuilder.Entity<ViewNeetOutMaterial>(entity =>
        {
            entity.ToView("View_NeetOutMaterial");
        });

        modelBuilder.Entity<ViewTaskOrder>(entity =>
        {
            entity.ToView("View_TaskOrder");
        });

        modelBuilder.Entity<Warehouse>(entity =>
        {
            entity.Property(e => e.IdWarehouse).ValueGeneratedNever();
            entity.Property(e => e.Parameter).HasComment("参数");
            entity.Property(e => e.Type)
                .HasDefaultValue("")
                .HasComment("类型");
            entity.Property(e => e.WarehouseCode).HasComment("仓库号");
            entity.Property(e => e.WarehouseName).HasComment("仓库描述");
            entity.Property(e => e.Xaxis).HasComment("排");
            entity.Property(e => e.Yaxis).HasComment("列");
            entity.Property(e => e.Zaxis).HasComment("高");
        });

        modelBuilder.Entity<WarehouseLine>(entity =>
        {
            entity.Property(e => e.IdWarehouseLine).ValueGeneratedNever();
            entity.Property(e => e.IsEnable).HasComment("是否使用");
            entity.Property(e => e.IsOccupy).HasComment("是否占用");
            entity.Property(e => e.Type).HasComment("仓库类型");
            entity.Property(e => e.Xaxis).HasComment("排");
            entity.Property(e => e.Yaxis).HasComment("列");
            entity.Property(e => e.Zaxis).HasComment("高");
        });

        modelBuilder.Entity<WorkerOrder>(entity =>
        {
            entity.Property(e => e.IdWorkerOrder).ValueGeneratedNever();
            entity.Property(e => e.BoxCode).HasComment("箱盒");
            entity.Property(e => e.EndPlace).HasComment("目标位置");
            entity.Property(e => e.StartPlace).HasComment("起始位置");
            entity.Property(e => e.Type).HasComment("上架or下架");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
